// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 下载 —————————————————————————————— //

  async remoteDownload(content) {
    const { state: { API, downParam, summary, detail }, getters: { GETTER } } = content
    const SUMMARY_TIP = API.transTip(summary.MAP.tipDown)
    const DETAIL_TIP = API.transTip(detail.MAP.tipDown)

    // 查询数据
    const [, arr1] = await summary.API.getList({ ...summary.param, ...downParam }, SUMMARY_TIP)
    const [, arr2] = await detail.API.getList({ ...detail.param, ...downParam }, DETAIL_TIP)

    // 表格转换
    const data1 = summary.refTable.getData(summary.API.transList(arr1))
    const data2 = detail.refTable.getData(detail.API.transList(arr2, { state: detail }))

    // 导出文档
    const sheet1 = { ...data1, sheetName: summary.MAP.WORD }
    const sheet2 = { ...data2, sheetName: detail.MAP.WORD }
    CORE.excelExport(GETTER.fileName, sheet1, sheet2)
  },
}
